package com.google.code.sprite.generate;

import org.apache.commons.io.FilenameUtils;
import java.io.File;
import com.google.code.sprite.conf.TableConfig;
import com.google.code.sprite.util.Util;

public class ServiceImplGenerate extends AbstractGenerate {

    public String getSubPackage() {
        return "service.impl";
    }

    public void writeToFile(TableConfig tableConfig, TableMetaData tableMetaData) {
        init(tableConfig, tableMetaData);
        String subDir = getJavaSubPackagePath();
        String fileName = FilenameUtils.concat(subDir, serviceImplClass +".java");
        writeToFile(fileName, generate());
    }


    public String generate() {
        File actionTemplate = getTemplateFile("ServiceImpl.java");
        if (!actionTemplate.exists()) {
            return "";
        }
        String content = Util.readContent(actionTemplate);
        content = replaceVar(content);
        content = content.replace("${package}", pkg + ".service.impl");
        return content;
    }

}
